const mongoose = require('mongoose')
const Schema = mongoose.Schema

const userSchema = mongoose.Schema({
  nickname: String,
  email: String,
  password: String,
  sex: {
    type: String,
    default: '秘密'
  },
  avatar: {
    type: String, 
    default: ''
  },
  groups: [{
    type: Schema.Types.ObjectId,
    ref: 'group'
  }],
  friends: [{
    type: Schema.Types.ObjectId,
    ref: 'user'
  }],
  createAt: {
    type: Date,
    default: new Date()
  },
  socket: {
    type: Schema.Types.ObjectId,
    ref: 'socket'
  },
  // 匹配状态 1-未开始匹配 2-等待匹配 3-匹配成功
  matchState: {
    type: Number,
    default: 1
  },
  matchUser: {
    type: Schema.Types.ObjectId,
    ref: 'user'
  },
  onlineState:{
    type: Boolean,
    default: true
  },
  lastUpdate: {
    type: Date,
    default: new Date('2018-01-01')
  },
  lastOnline: {
    type: Date,
    default: new Date()
  },
  place: {
    type: String,
    default: '火星'
  },
  shield: [{
    type: Schema.Types.ObjectId,
    ref: 'user'
  }]
})

module.exports = mongoose.model('user', userSchema)
